package com.ruoyi.user.controller.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SpffUsers;
import com.ruoyi.system.service.ISpffUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户Controller
 * 
 * @author xjj
 * @date 2025-09-11
 */
@RestController
@RequestMapping("/userApi/users")
public class USpffUsersController extends BaseController
{
    @Autowired
    private ISpffUsersService spffUsersService;

    /**
     * 查询用户列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SpffUsers spffUsers)
    {
        startPage();
        List<SpffUsers> list = spffUsersService.selectSpffUsersList(spffUsers);
        return getDataTable(list);
    }

    /**
     * 导出用户列表
     */

    @Log(title = "用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SpffUsers spffUsers)
    {
        List<SpffUsers> list = spffUsersService.selectSpffUsersList(spffUsers);
        ExcelUtil<SpffUsers> util = new ExcelUtil<SpffUsers>(SpffUsers.class);
        util.exportExcel(response, list, "用户数据");
    }

    /**
     * 获取用户详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(spffUsersService.selectSpffUsersById(id));
    }

//    /**
//     * 新增用户
//     */
//    @Log(title = "用户", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody SpffUsers spffUsers)
//    {
//        return toAjax(spffUsersService.insertSpffUsers(spffUsers));
//    }

    /**
     * 修改用户
     */
    @Log(title = "用户", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody SpffUsers spffUsers)
    {
        return toAjax(spffUsersService.updateSpffUsers(spffUsers));
    }

}
